/**
 * Created by Administrator on 2015/5/8.
 */
define(['jquery', 'tagsinput'], function($){
    $(function() {//初始化标签输入/
        /*
         The twitter.github.io/typeahead.js not compatible with bootstrap 3.
         You can use this Typeahead which is compatible with twitter bootstrap 3 https://github.com/bassjobsen/Bootstrap-3-Typeahead
         */
        $('input[data-role=tagsinput], select[multiple][data-role=tagsinput]').each(function(i, n){
            var $that = $(n);
            var options = {
                typeahead: {
                    source: function(query){
                        var url = '/article/query' + $that.attr('data-type').replace(/^\w/, function(str){
                                return str.toUpperCase();
                            }) + '/';
                        return $.get(url + query);
                    }
                }
            };
            if($that.attr('data-maxtags')){
                options.maxTags = +$that.attr('data-maxtags');
            }
            $that.tagsinput(options);
        });
    });
});
